/*
 * GWT Portlets Framework (http://code.google.com/p/gwtportlets/)
 * Copyright 2009 Business Systems Group (Africa)
 *
 * This file is part of GWT Portlets.
 *
 * GWT Portlets is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * GWT Portlets is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with GWT Portlets.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.gwtportlets.portlet.client;

import com.google.gwt.user.client.ui.Widget;

/**
 * Base class for widget factories. Preserves the primary style name.
 */
public abstract class AbstractWidgetFactory<T extends Widget>
        implements WidgetFactory<T> {

    protected String styleName;

    protected AbstractWidgetFactory() {
    }

    protected AbstractWidgetFactory(Widget w) {
        styleName = w.getStyleName();
    }

    public void refresh(T w) {
        if (styleName != null) {
            w.setStyleName(styleName);
        }
    }

    public void accept(WidgetFactoryVisitor v) {
        v.visit(this);
    }

}
